<?php
// $Id$

/**
 * @file
 * Administration page callbacks for the FriendFeed OAuth module.
 */

/**
 * Form builder. Configure FriendFeed OAuth.
 *
 */
function friendfeed_oauth_admin_settings() {
  $form['friendfeed_oauth_tokens'] = array(
    '#title' => t('OAuth Tokens'),
    '#type' => 'fieldset',
    '#description' => t('Use these options to specify the secret tokens for accessing FriendFeed via OAuth.'),
  );

  // General Feed Settings
  $form['friendfeed_oauth_tokens']['friendfeed_oauth_consumer_key'] = array(
    '#type' => 'textfield',
    '#title' => t('Consumer key'),
    '#default_value' => variable_get('friendfeed_oauth_consumer_key', ''),
    '#size' => 45,
    '#maxlength' => 300,
    '#required' => TRUE,
  );

  $form['friendfeed_oauth_tokens']['friendfeed_oauth_consumer_secret'] = array(
    '#type' => 'textfield',
    '#title' => t('Consumer secret'),
    '#default_value' => variable_get('friendfeed_oauth_consumer_secret', ''),
    '#size' => 65,
    '#maxlength' => 300,
    '#required' => TRUE,
  );

  $form['friendfeed_oauth_tokens']['friendfeed_oauth_signature_method'] = array(
    '#type' => 'select',
    '#title' => t('Signature method'),
    '#default_value' => variable_get('friendfeed_oauth_signature_method', 'HMAC-SHA1'),
    '#options' => array(
      'HMAC-SHA1' => t('HMAC-SHA1'),
      'RSA-SHA1' => t('RSA-SHA1 (Not implemented)'),
      'PLAINTEXT' => t('Plaintext (Not implemented)'),
    ),
    '#description' => t('Select the signature method. HMAC-SHA1 is recommended for most cases. Do not use Plaintext unless you&rsquo;re using HTTPS.'),
  );

  $form['friendfeed_oauth_urls'] = array(
    '#title' => t('OAuth URLs'),
    '#type' => 'fieldset',
    '#description' => t('Use these options to specify the URLs for accessing FriendFeed via OAuth.'),
  );

  $form['friendfeed_oauth_urls']['friendfeed_oauth_callback_url'] = array(
    '#type' => 'textfield',
    '#title' => t('Callback/Destination URL'),
    '#default_value' => variable_get('friendfeed_oauth_callback_url', 'oauth'),
    '#size' => 45,
    '#maxlength' => 300,
    '#required' => TRUE,
    '#type' => 'textfield',
    '#description' => t('Specify where Drupal should go to once the user is authorized, relative to the site root. Use <front> for the front page. At FriendFeed, specify %callback_url as the callback URL.', array('%callback_url' => url(NULL, array('absolute' =>TRUE)) . 'friendfeed/oauth/authorize')),
    '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='),
    '#required' => TRUE,
  );

  $form['friendfeed_oauth_urls']['friendfeed_oauth_request_token_url'] = array(
    '#type' => 'textfield',
    '#title' => t('Request token URL'),
    '#default_value' => variable_get('friendfeed_oauth_request_token_url', 'https://friendfeed.com/account/oauth/request_token'),
    '#size' => 45,
    '#maxlength' => 300,
    '#required' => TRUE,
    '#type' => 'textfield',
    '#required' => TRUE,
  );

  $form['friendfeed_oauth_urls']['friendfeed_oauth_access_token_url'] = array(
    '#type' => 'textfield',
    '#title' => t('Access token URL'),
    '#default_value' => variable_get('friendfeed_oauth_access_token_url', 'https://friendfeed.com/account/oauth/access_token'),
    '#size' => 45,
    '#maxlength' => 300,
    '#required' => TRUE,
    '#type' => 'textfield',
    '#required' => TRUE,
  );

  $form['friendfeed_oauth_urls']['friendfeed_oauth_authorize_url'] = array(
    '#type' => 'textfield',
    '#title' => t('Request token URL'),
    '#default_value' => variable_get('friendfeed_oauth_authorize_url', 'https://friendfeed.com/account/oauth/authorize'),
    '#size' => 45,
    '#maxlength' => 300,
    '#required' => TRUE,
    '#type' => 'textfield',
    '#required' => TRUE,
  );

  return system_settings_form($form);
}